<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Catalog</title>
</head>
<body>
<body background="../img/bg.jpg"> 
	<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<center>
<br><br><br><br>
<h1>Adauga note</h1>
	<?
error_reporting (E_ALL ^ E_NOTICE);
include('auth.php');
include('../config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {die('Failed to connect to server: ' . mysql_error());}
           
$db = mysql_select_db(DB_DATABASE);
if(!$db) {die("Unable to select database");}
?>
<b>

<?
function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}


//verifica semestru
if (isset($_GET['sem']) && isset($_GET['materieid']) && isset($_GET['elevid'])) {
if ($_GET['sem']!="gen") {
	$elevid = $_GET['elevid'];
	$materieid = $_GET['materieid'];
	$sem = $_GET['sem'];
	$suma = 0;
	$nr_note = 0;
	$query_note = mysql_query("SELECT `nota` FROM `note`  WHERE elev_id='".$elevid."' and  materie_id='".$materieid."'");
	while($row = mysql_fetch_array($query_note)) { 
		$suma += $row['nota'];
		$nr_note++;
	}
	$media = $suma/$nr_note;
$mysql=mysql_query("insert into medii(elev_id,materie_id,medie,sem) values ('".$elevid."','".$materieid."','".$media."','".$sem."')");
} else {
	$elevid = $_GET['elevid'];
	$materieid = $_GET['materieid'];
	$sem = $_GET['sem'];
	$suma = 0;
	$nr_note = 0;
	$query_note = mysql_query("SELECT `nota` FROM `note` WHERE elev_id='".$elevid."'");
	while($row = mysql_fetch_array($query_note)) { 
		$suma += $row['nota'];
		$nr_note++;
	}
	$media = $suma/$nr_note;
$mysql=mysql_query("insert into elev(mediegen) values ('".$media."') where id='".$elevid."'");
}
	header('location: admin.php');
} 


?>
</font>
</center>
</body>
</html>